//
//  LGStatusOriginalView.swift
//  LGWeibo
//
//  Created by 李更 on 8/14/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit

class LGStatusOriginalView: UIView {
    
    //定义一个Viewmodel供外界调用
    var StatusViewModel : LGStatusViewModel?{
        didSet{
            headImageView.lg_setImageWithString(StatusViewModel?.statusModel?.user?.profile_image_url, placeholderImage: "avatar_default")
            nameLable.text = StatusViewModel?.statusModel?.user?.name
            timeLable.text = "时间"
           sourceLable.text = "来自传智播客31期微博"
            contentLable.text = StatusViewModel?.statusModel?.text
            membershipImageView.image = StatusViewModel?.mbrankImage
            avatarImageView.image = StatusViewModel?.verifiedImage
            
            
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        backgroundColor = RandomColor()
        //添加控件
        addSubview(headImageView)
        addSubview(nameLable)
        addSubview(timeLable)
        addSubview(avatarImageView)
        addSubview(sourceLable)
        addSubview(contentLable)
        addSubview(membershipImageView)
        addSubview(PictureView)
        
        //添加约束
        headImageView.snp_makeConstraints { (make) in
            make.top.leading.equalTo(10)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        //02
        nameLable.snp_makeConstraints { (make) in
            make.leading.equalTo(headImageView.snp_trailing).offset(10)
            make.top.equalTo(headImageView)
        }
        //03
        timeLable.snp_makeConstraints { (make) in
            make.leading.equalTo(nameLable)
            make.bottom.equalTo(headImageView)
        }
        
        //04
        membershipImageView.snp_makeConstraints { (make) in
            make.leading.equalTo(nameLable.snp_trailing).offset(10)
            make.centerY.equalTo(nameLable)
        }
        //05
        sourceLable.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLable.snp_trailing).offset(10)
            make.bottom.equalTo(timeLable)
            
        }
        //06
        avatarImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        //07
        contentLable.snp_makeConstraints { (make) in
            make.top.equalTo(headImageView.snp_bottom).offset(10)
            make.leading.equalTo(10)
        }
        //08
        PictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLable.snp_bottom).offset(10)
            make.leading.equalTo((SCREENW - 250)/2)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(PictureView).offset(10)
        }
        
        
    }
    
    
    //懒加载控件
    private lazy var headImageView : UIImageView = UIImageView(imageName: "avatar_default")
    private lazy var nameLable : UILabel = {
        let namelable = UILabel()
        
        namelable.text = "名字'"
        
        namelable.font = UIFont.systemFontOfSize(15)
        
        namelable.textColor = UIColor.darkGrayColor()
        return namelable
        }()
    //等级
    private lazy var membershipImageView : UIImageView = UIImageView(imageName: "common_icon_membership")
    //时间
    private lazy var timeLable : UILabel = UILabel(textColor: UIColor.orangeColor(), textSize: 10)
    //认证
    private lazy var avatarImageView : UIImageView = UIImageView(imageName: "avatar_vgirl")
    //来源
    private lazy var sourceLable : UILabel = UILabel(textColor: UIColor.grayColor(), textSize: 10)
    
    //微博正文
    private lazy var contentLable : UILabel = UILabel(textColor: UIColor.blackColor(), textSize: 15, maxWidth: SCREENW-20)
    
    //添加图片
    private var PictureView : LGStatusPictureView = LGStatusPictureView()
        
    }
    


